package JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * JDBC JAVA 数据库连接
 */
public class JDBCDemo1 {
    public static void main(String[] args) {
        try {
            //1.加载驱动
            Class.forName("com.mysql.cj.jdbc.Driver");
            //2.建立连接
            String url = "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true";
            Connection connection = DriverManager.getConnection(url, "root", "root");
            System.out.println("连接成功");
            //3.
            Statement statement = connection.createStatement();
            String sql = "CREATE TABLE user("+
                         "id INT PRIMARY KEY AUTO_INCREMENT, "+
                         "username VARCHAR(30), "+
                         "password VARCHAR(30), "+
                         "nickname VARCHAR(20), "+
                         "age INT(3)"+
                         ")";
            statement.execute(sql);
            System.out.println("创建成功");

            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
